package cn.terminus.biz.customer.settledenterprisebillinfo;

import cn.terminus.biz.customer.common.AbstractTerminusManager;
import cn.terminus.common.customer.bean.settledenterprisebillinfo.dto.*;
import cn.terminus.data.customer.settledenterprisebillinfo.dao.SettledEnterpriseBillInfoDao;
import cn.terminus.result.common.exception.DataAccessException;
import cn.terminus.result.common.page.TerminusPageAble;
import cn.terminus.result.common.page.TerminusPageInfo;
import cn.terminus.result.common.util.BeanCopyUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * (SettledEnterpriseBillInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-07-08 11:19:04
 */
@Component
public class SettledEnterpriseBillInfoManager extends AbstractTerminusManager {
    @Autowired
    private SettledEnterpriseBillInfoDao settledEnterpriseBillInfoDao;

    public Integer add(SettledEnterpriseBillInfoNewDto dto) throws DataAccessException {
        try {
            return settledEnterpriseBillInfoDao.add(dto);
        } catch (Exception e) {
            logger.error("SettledEnterpriseBillInfoManager新增失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer update(SettledEnterpriseBillInfoNewDto dto) throws DataAccessException {
        try {
            return settledEnterpriseBillInfoDao.update(dto);
        } catch (Exception e) {
            logger.error("SettledEnterpriseBillInfoManager更新失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<SettledEnterpriseBillInfoResultDto> gets(SettledEnterpriseBillInfoGetsDto dto) throws DataAccessException {
        try {
            return settledEnterpriseBillInfoDao.gets(dto);
        } catch (Exception e) {
            logger.error("SettledEnterpriseBillInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public List<SettledEnterpriseBillInfoResultDto> query(SettledEnterpriseBillInfoQueryDto dto) throws DataAccessException {
        try {
            return settledEnterpriseBillInfoDao.query(dto);
        } catch (Exception e) {
            logger.error("SettledEnterpriseBillInfoManager查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public Integer delete(SettledEnterpriseBillInfoDeleteDto dto) throws DataAccessException {
        try {
            return settledEnterpriseBillInfoDao.delete(dto);
        } catch (Exception e) {
            logger.error("SettledEnterpriseBillInfoManager删除失败，原因：", e);
            throw new DataAccessException(e);
        }
    }

    public TerminusPageAble<SettledEnterpriseBillInfoResultDto> page(SettledEnterpriseBillInfoQueryDto dto, TerminusPageInfo page) throws DataAccessException {
        try {
            PageHelper.startPage(page.getCurrentPage(), page.getPageSize());
            Page<SettledEnterpriseBillInfoResultDto> result = (Page<SettledEnterpriseBillInfoResultDto>) settledEnterpriseBillInfoDao.query(dto);
            return new TerminusPageAble<>(BeanCopyUtils.copy(result.getResult(), SettledEnterpriseBillInfoResultDto.class), page, result.getTotal());
        } catch (Exception e) {
            logger.error("SettledEnterpriseBillInfoManager分页查询失败，原因：", e);
            throw new DataAccessException(e);
        }
    }
}
